package log

import (
	"fmt"

	"core/contract/log"
	logType "core/enum/log"
	"core/model/config"
)

type Factory struct {
	logger map[logType.Value]log.ILog
}

func (f Factory) Build(v ...logType.Value) log.ILog {
	t := logType.SeverLog
	if len(v) > 0 {
		t = v[0]
	}

	logger, ok := f.logger[t]
	if !ok {
		panic(fmt.Sprintf("无效log类型:%v", v))
	}

	return logger
}

func NewLogFactory(config *config.Config) (log.ILogFactory, error) {
	serverLog, err := newServerLogSvc(config)
	if err != nil {
		return nil, err
	}

	cronLog, err := newCronLogSvc(config)
	if err != nil {
		return nil, err
	}

	return Factory{
		logger: map[logType.Value]log.ILog{
			logType.SeverLog: serverLog,
			logType.CronLog:  cronLog,
		},
	}, nil
}
